﻿using System;
using System.Xml.Serialization;
using cndp.Model.IModel;

namespace cndp.Model
{
    /// <summary>
    /// Diverscore - Diverscore innehåller information om hur mycket poäng en simhoppare fått för ett hopp.
    /// </summary>
    [Serializable]
    public class Diverscore : IComparable<Diverscore>
    {
        #region Variables/Properties

        [XmlElement("DIVER")]
        public Diver Key { get; set; }
        [XmlElement("VALUE")]
        public double Value { get; set; }

        #endregion

        #region Constructor

        public Diverscore(Diver key, double value)
        {
            Key = key;
            Value = value;
        }

        public Diverscore()
        {
        }

        #endregion

        #region Compare/Equals

        public int CompareTo(Diverscore other)
        {
            if (Value < other.Value)
            {
                return 1;
            }
            if (Value == other.Value)
            {
                return 0;
            }
            return -1;
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            var objAsDiver = obj as Diverscore;
            if (objAsDiver == null) return false;
            return Equals(objAsDiver);
        }

        public bool Equals(Diverscore other)
        {
            if (other == null) return false;
            return (Key.PersonalCodeNumber.Equals(other.Key.PersonalCodeNumber));
        }

        #endregion
    }
}